<html>
<head><meta charset="utf-8"><title>Removing macros from top level? · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html">Removing macros from top level?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="203827733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203827733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203827733">(Jul 14 2020 at 12:39)</a>:</h4>
<p>An exciting development in the last month or so that we haven't really discussed is that we are now merging macros at paths (first <code>core::ptr::raw!/raw_mut!</code>, now also <code>core::task::ready!</code>). Several of the macros which are auto-imported from std are actually rarely used and would not have been added to the prelude except that macros originally had to be exported that way. Should we consider exposing some of these macros at paths and removing them from the prelude in the next edition?</p>



<a name="203827923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203827923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203827923">(Jul 14 2020 at 12:41)</a>:</h4>
<p>I'm thinking of things like <code>is_x86_feature_detected</code>, the include macros, maybe line/column/module_path, maybe thread_local. The macros that are mainly used for debugging purposes, the panics, formatting macros, vec, all should stay in the prelude IMO.</p>



<a name="203837136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203837136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203837136">(Jul 14 2020 at 14:06)</a>:</h4>
<p>There was some discussion about moving asm! to core::arch::$ARCH::asm! in the RFC.</p>



<a name="203852086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203852086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203852086">(Jul 14 2020 at 16:05)</a>:</h4>
<p>line/column/module_path are "used for debugging purposes"</p>



<a name="203853212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203853212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203853212">(Jul 14 2020 at 16:15)</a>:</h4>
<p>I would love to be able to move macros out of the std crate root. Even without an edition, I think could make sense to move the macros to better locations and then reexport them in the root for back compat.</p>



<a name="203854644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203854644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203854644">(Jul 14 2020 at 16:27)</a>:</h4>
<p>I'm not sure if it's possible to remove macros in an edition boundary, or in general to change the standard library in an edition boundary.</p>



<a name="203855132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203855132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203855132">(Jul 14 2020 at 16:31)</a>:</h4>
<p>I don't think that functionality exists now, but it definitely seems plausible to teach the compiler to ignore certain reexports when certain editions are selected</p>



<a name="203855249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203855249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203855249">(Jul 14 2020 at 16:32)</a>:</h4>
<p>Yeah it seems <em>technically</em> possible, though politically possible maybe not.</p>



<a name="203856158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203856158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203856158">(Jul 14 2020 at 16:40)</a>:</h4>
<p>It has been suggested that a new edition could use a different implicit prelude path though</p>



<a name="203870423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203870423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Peter Rabbit <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203870423">(Jul 14 2020 at 18:36)</a>:</h4>
<p>I'm on board with moving macros to non-root locations and phasing out some of those re-exports in a future edition.</p>



<a name="203871537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203871537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203871537">(Jul 14 2020 at 18:46)</a>:</h4>
<p><span class="user-mention" data-user-id="256759">@boats</span> will "macros have their own path" be stabilized during a particular release or is it just generally in the pipeline?</p>



<a name="203882213"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203882213" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203882213">(Jul 14 2020 at 20:18)</a>:</h4>
<p>@Lokathor we just have 2 macros going into nightly that are at paths. The feature has existed since around 2018 but we haven't used it in std before. I'm not sure if it presents any problems for 2015 edition crates</p>



<a name="203882280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203882280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203882280">(Jul 14 2020 at 20:19)</a>:</h4>
<p>We've never implemented support, but editions can remove paths without any issue. They just can't redefine paths (once a path is used in one edition, it can never be used to mean  something with a different definition in a future edition.)</p>



<a name="203882529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203882529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203882529">(Jul 14 2020 at 20:21)</a>:</h4>
<p>Editions can't remove impls, or can't without a lot of extra machinery to make sure cross-edition crates stay coherent</p>



<a name="203891798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203891798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203891798">(Jul 14 2020 at 21:38)</a>:</h4>
<p>Oh my. Can user crates make macros at paths? I've still been using <code>#[macro_export]</code> and having my macros be at the top level of the crate.</p>



<a name="203906782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203906782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203906782">(Jul 15 2020 at 01:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F/near/203891798">said</a>:</p>
<blockquote>
<p>Oh my. Can user crates make macros at paths? I've still been using <code>#[macro_export]</code> and having my macros be at the top level of the crate.</p>
</blockquote>
<p>Yes, they can, as of roughly around the 2018 edition.</p>



<a name="203906796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203906796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203906796">(Jul 15 2020 at 01:00)</a>:</h4>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> That does seem like the cleanest way to do it.</p>



<a name="203906839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203906839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203906839">(Jul 15 2020 at 01:01)</a>:</h4>
<p>Personally, I would be very hesitant to cause the churn that removing a common macro would cause. We could certainly implement the technical means to do so. But would it be worth pushing people to change their code like that, or should we just soft-deprecate the old names and tell people to use the new ones?</p>



<a name="203906930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203906930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203906930">(Jul 15 2020 at 01:03)</a>:</h4>
<p>(how do you do that? because when i type <code>pub macro_rules!</code> the compiler says i can't put visibility on macros)</p>



<a name="203913953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203913953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203913953">(Jul 15 2020 at 03:44)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> You still have to write <code>#[macro_export]</code>, but you can now import using <code>use</code> with a path.</p>



<a name="203913956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203913956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203913956">(Jul 15 2020 at 03:44)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/edition-guide/rust-2018/macros/macro-changes.html">https://doc.rust-lang.org/nightly/edition-guide/rust-2018/macros/macro-changes.html</a></p>



<a name="203915144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203915144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203915144">(Jul 15 2020 at 04:12)</a>:</h4>
<p>Ah, okay. I follow now. I've actually had to import alloc::vec::vec before so i should have realized.</p>



<a name="203921400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Removing%20macros%20from%20top%20level%3F/near/203921400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Removing.20macros.20from.20top.20level.3F.html#203921400">(Jul 15 2020 at 06:48)</a>:</h4>
<p>rustdoc is still having some issues with <code>pub macro</code> though it seems: <a href="https://github.com/rust-lang/rust/issues/74355">https://github.com/rust-lang/rust/issues/74355</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>